<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>

		<p>111</p>
		<p>222</p>

		<div id="div1">

		</div>

		<script>
			//HTMLCollection 对象
			//获取文档中所有的p元素
			var x = document.getElementsByTagName('p');
			//访问第二个p元素
			var y = x[1];

			//HTMLCollection 对象 length 属性
			document.getElementById("div1").innerHTML = x.length;

			//修改所有 <p> 元素的背景颜色:
			for (var i in x) {
				x[i].style.backgroundColor = "red";
			}
		</script>
	</body>
</html>